<template>
  <!-- 新增/变更附件 -->
  <div>
    <span v-if="currentFileInfo.fileName">当前选中文档：<el-tag type="primary">{{ currentFileInfo.fileName }}</el-tag></span>
    <el-table :data="documentList" style="width:100%;margin-top:8px;" :highlight-current-row="true" @row-click="handleTaskClick">
      <el-table-column label="文档名称" align="left" prop="fileName" min-width="180" :show-overflow-tooltip="true" />
      <el-table-column label="文档大小" align="center" prop="fileSize" min-width="120" :formatter="formatFileSize" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">{{ scope.row.createTime|moment }}</template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { Loading } from 'element-ui';
  // import { listDocument } from "@/api/project/documentCenter";
  import { formatFileSize } from '@/api/common/common';
  export default {
    name: 'FileAdd',
    data(){
      return {
        documentList:[],
        currentFileInfo:{}, // 当前选中文档
      }
    },
    methods:{
      // 文档列表
      getDocumentList() {
        listDocument({
          pageNum: 1,
          pageSize: 999,
          projectId:"",
          fileName:""
        }).then(ret => {
          if(ret.code == 200){
            this.documentList = ret.rows;
          }else{
            this.$message.error(ret.msg);
          }
        }).catch(err=>{
          this.loading = false;
        });
      },
      // 格式化文件大小
      formatFileSize(row, column){
        return formatFileSize(row.fileSize);
      },

      handleTaskClick(row, column, event){
        this.currentFileInfo = row;
      },
    }
  }
</script>

<style scoped>
  .el-form{
    background-color:#FFF;
    padding:10px 0px;
    margin-bottom: 10px;
    text-align:left;
  }
  .el-form-item{text-align:left;}
  .el-input{width:215px;}
</style>
